package com.javaIO.demo1;

import java.io.FileInputStream;
import java.io.IOException;

public class Test4 {
    public static void main(String[] args) {

        FileInputStream f = null;
        try {
            f = new FileInputStream("D:\\SoftDevelopment\\Java\\file\\demo1.txt");
//            int by;
//            while ((by = f.read()) != -1) {
//                System.out.print((char) by);
//            }
            //字节数组读取
            byte[] bytes = new byte[10];
            //返回值，实际读取的内容
            System.out.println("第一次读取");
            int len = f.read(bytes);
            System.out.println(len);
            System.out.println(new String(bytes, 0, len));

            /**
             * 换行符：\r\n ----占两个字符
             */
            System.out.println("第二次读取");
            len = f.read(bytes);
            System.out.println(len);
            System.out.println(new String(bytes, 0, len));
            
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            if (f != null) {
                try {
                    f.close();
                } catch (IOException e) {
                    System.out.println(e.getMessage());
                }
            }

        }
    }
}
